def jury_stability_test(denominator_coeffs):
    """
    通过朱里准则验证系统稳定性
    参数:
        denominator_coeffs (list): 系统传递函数分母多项式的系数，从最高阶到最低阶
    返回:
        tuple: (是否稳定, 详细信息, 朱里表)
    """
    vvd = []  # 朱里表
    v = denominator_coeffs.copy()
    
    # 检查输入有效性
    if not v:
        return False, "空系数列表", []
    if len(v) < 2:
        return False, "系统阶数过低，至少需要1阶系统", []
    
    # 构建朱里表
    vvd.append(v.copy())  # 第一行
    v.reverse()
    vvd.append(v.copy())  # 第二行(反转)
    
    i = 2
    while True:
        v = []
        # 计算乘数 (an/a0)
        if vvd[i-2][0] == 0:
            return False, f"除零错误：行{i-1}的第一个元素为零", vvd
        
        mult = vvd[i-2][-1] / vvd[i-2][0]
        
        # 计算新行
        for j in range(len(vvd[i-2])-1):
            v.append(vvd[i-2][j] - vvd[i-1][j] * mult)
        
        vvd.append(v.copy())
        
        # 结束条件
        if len(v) == 1:
            break
            
        # 添加反转行
        v.reverse()
        vvd.append(v.copy())
        i += 2
    
    # 检查稳定性
    problem_row = -1
    for i in range(0, len(vvd), 2):
        if vvd[i][0] <= 0:
            problem_row = i
            break
    
    if problem_row == -1:
        return True, "所有根都在单位圆内，系统稳定", vvd
    else:
        # 找出具体问题
        if problem_row == 0:
            problem = f"首行第一个元素 {vvd[0][0]} ≤ 0"
        elif problem_row == 2 and len(vvd[0]) > 1:
            a0 = vvd[0][-1]
            an = vvd[0][0]
            if abs(a0) >= abs(an):
                problem = f"|a0| = {abs(a0)} ≥ |an| = {abs(an)}"
            else:
                problem = f"行{problem_row+1}第一个元素 {vvd[problem_row][0]} ≤ 0"
        else:
            problem = f"行{problem_row+1}第一个元素 {vvd[problem_row][0]} ≤ 0"
        
        return False, f"稳定性条件不满足：{problem}", vvd

def print_jury_table(vvd, is_stable, message):
    """打印朱里表结果"""
    print("\n朱里准则稳定性分析结果:")
    print("=" * 60)
    
    if not is_stable:
        print(f"系统不稳定！原因: {message}")
        print("问题出现在以下朱里表中:")
    else:
        print("系统稳定！完整朱里表如下:")
    
    print("-" * 60)
    print("{:<8s} {:<30s} {:<15s}".format("行号", "系数", "类型"))
    print("-" * 60)
    
    for i, row in enumerate(vvd):
        row_type = "原始多项式" if i == 0 else "反转系数" if i == 1 else "计算行" if i % 2 == 0 else "反转行"
        coeffs_str = "  ".join([f"{x:8.4f}" for x in row])
        print(f"{i+1:<8d} {coeffs_str:<30s} {row_type:<15s}")
    
    print("=" * 60)

# 测试用例
if __name__ == "__main__":
    test_cases = [
        [5, 5, 2]
    ]
    
    for i, coeffs in enumerate(test_cases):
        print(f"\n测试用例 {i+1}: {coeffs}")
        is_stable, message, jury_array = jury_stability_test(coeffs)
        print_jury_table(jury_array, is_stable, message)